package com.example.demo.controller;


import com.example.demo.model.SysAcl;
import com.example.demo.responsehandler.ResponseUtil;
import com.example.demo.service.ISysAclService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.demo.codegenerator.BaseController;

import java.io.IOException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Webgasd
 * @since 2021-04-25
 */
@RestController
@RequestMapping("/demo/sys-acl")
@Api(value = "/demo/sys-acl", tags = {"功能点控制器"})
public class SysAclController extends BaseController {
    @Autowired
    private ISysAclService sysAclService;

    @ApiOperation(value = "根据二级模块的主键码获取其下的功能点")
    @ApiImplicitParams(value = {@ApiImplicitParam(name = "APP_KEY", value = "拦截器验证K", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header"),
            @ApiImplicitParam(name = "SECRET", value = "拦截器验证V", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header"),
            @ApiImplicitParam(name = "aclModuleId", value = "二级模块的主键码", dataType = "int", defaultValue = "0", example = "0", required = true, paramType = "query")})
    @GetMapping("/getListByAclModuleId")
    public void getListByAclModuleId(@RequestParam("aclModuleId") Integer aclModuleId) throws IOException {
        ResponseUtil.showMessage("success", "获取成功", sysAclService.getListByAclModuleId(aclModuleId));
    }

    @ApiOperation(value = "添加某一条功能点信息")
    @ApiImplicitParams(value = {@ApiImplicitParam(name = "APP_KEY", value = "拦截器验证K", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header"),
            @ApiImplicitParam(name = "SECRET", value = "拦截器验证V", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header")})
    @PostMapping("/saveAclModule")
    public void saveAclModule(@RequestBody SysAcl sysAcl) throws IOException {
        ResponseUtil.showMessage("success", "添加成功", sysAclService.saveAclModule(sysAcl));
    }

    @ApiOperation(value = "更新某一条功能点信息")
    @ApiImplicitParams(value = {@ApiImplicitParam(name = "APP_KEY", value = "拦截器验证K", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header"),
            @ApiImplicitParam(name = "SECRET", value = "拦截器验证V", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header")})
    @PutMapping("/updateAclModule")
    public void updateAclModule(@RequestBody SysAcl sysAcl) throws IOException {
        ResponseUtil.showMessage("success", "更新成功", sysAclService.updateAclModule(sysAcl));
    }

    @ApiOperation(value = "根据功能点id删除某一条功能点信息")
    @ApiImplicitParams(value = {@ApiImplicitParam(name = "APP_KEY", value = "拦截器验证K", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header"),
            @ApiImplicitParam(name = "SECRET", value = "拦截器验证V", dataType = "String", defaultValue = "111", example = "111", required = true, paramType = "header"),
            @ApiImplicitParam(name = "id", value = "功能点id", dataType = "int", defaultValue = "0", example = "0", required = true, paramType = "query")})
    @DeleteMapping("/deleteAclById")
    public void deleteAclById(@RequestParam("id") Integer id) throws IOException {
        ResponseUtil.showMessage("success", "删除成功", sysAclService.deleteAclById(id));
    }
}
